import React from 'react';
import { View, Image, Linking } from 'react-native';
import { Lt, Color, Nav, Label, Jpp, Jx, Images, Dialog, Navigator, Rlist, Flist, Touch, Build, Fimage } from "../_utils";
import { Net, NET_NT, NET_GET, NET_RI } from "../_net"
import { ViewLine } from '../_util';

// 常见问题
export class Questions extends React.PureComponent{
    constructor(props){
        super(props);

        this.onLoad = this.onLoad.bind(this);
        this.onItem = this.onItem.bind(this);
    }
    static navigationOptions = {
        ...Nav.options,
        headerTitle: "常见问题",
    }
    onClick(data){
        Navigator.push("Question", {data});
    }
    onLoad(params){
        Net.request("advice/problem", params.pagination, { NET_NT, params}).then(r=>{
            if(r.data){
                params.add(r.data.pageData);
            }else{
                params.add();
            }
        });
    }
    onItem(params){
        const item = params.item;
        return <Touch onPress={this.onClick.bind(this,item)}>
            <View style={{marginVertical:20, marginLeft:Lt.margin, flexDirection:"row", justifyContent:"space-between", alignItems:"center"}}>
                <Label style={{fontSize:Lt.c16, color:Color.c3, flexShrink:1}}>{item.title}</Label>
                <View style={{flexDirection:"row", alignItems:"center"}}>
                    <Label style={{color:Color.c9}}>{Jx.toDate(item.createtime, "", false)}</Label>
                    <Image source={Images.you}/>
                </View>
            </View>
        </Touch>
    }
    render(){
        return <View style = {{flex:1, backgroundColor:"white"}}>
            <Nav.StatusBar/>
            <Flist 
                onLoad = {this.onLoad}
                onItem = {this.onItem}
                ItemSeparatorComponent = {ViewLine}
            />
        </View>;
    }
}


// 常见问题  某个问题详情
export class Question extends React.PureComponent{
    constructor(props){
        super(props);
        const {data} = this.props.navigation.state.params;
        this.state = {
            preData : data,
        }
    }
    static navigationOptions = {
        ...Nav.options,
        headerTitle: "常见问题",
    }

    render(){
        const preData = this.state.preData;
        return <View style = {{flex:1, backgroundColor:"white"}}>
            <Nav.StatusBar/>
            <Rlist style={{padding:Lt.pad}}>
                <Label style={{fontSize:Lt.c20, fontWeight:"900", color:Color.c3, marginTop:20,}}>{preData.title}元</Label>
                <Label style={{color:Color.c9, marginTop:5, marginBottom:20,}}>{Jx.toDate(preData.createtime)}</Label>
                <Label style={{fontSize:Lt.c16, color:Color.c3}}>
                    <Label style={{opacity:0, color:Color.transparent}}>{"缩进"}</Label>
                    {preData.detail}
                </Label>
            </Rlist>
        </View>;
    }
}

const c_text = "有限公司是一家快速成长的创新型企业，我司通过云计算，大数据，CPS,CPA付费推广等尖端领先技术为中小企业打造移动互联王时代的智慧商业整体解决方案。依托专业的网络营销顾问团队和强大的技术研发团队，在移动端构建成熟的一站式服务模式，给广大网购用户提供了打折扣购物便利。"
const c_text2 = "选择我们·造有价值的企业建站服务 专注营销型网站建设、 app定制开发、 企业手机网站、网络营销策划、企业电商服务、微信服务号开发、微信小程序开发及网站推广服务";
const c_link = "https://www.baidu.com/";

// 联系我们
export class Contact extends React.PureComponent{
    constructor(props){
        super(props);
        this.state = {
            image2 : "",
        }
    }
    static navigationOptions = {
        ...Nav.options,
        headerTitle: "联系我们",
    }
    componentWillMount(){
        Net.request("advice/contact", null, {NET_GET, NET_NT, NET_RI}).then(r=>{
            if(r.data){
                this.setState({image2:r.data});
            }
        });
    }
    render(){
        return <View style = {{flex:1, backgroundColor:"white"}}>
            <Nav.StatusBar/>
            <Rlist style={{alignItems:"center", paddingVertical:30}}>
                <Image source={Images.logo} style={{minWidth:100, minHeight:100, width:"25%", height:Jpp.width/4}}/>
                <Label style={{fontSize:Lt.c18, color:Color.c6, marginTop:Lt.margin, marginBottom:30}}>{Jpp.gameName} {Build.versionName}</Label>
                {/* <Touch onPress={this.onLink.bind(this, c_link)}>
                    <Label style={{fontSize:Lt.c16, color:Color.c3, marginHorizontal:20, textDecorationLine:"underline"}}>{c_link}</Label>
                </Touch> */}
                <Label style={{fontSize:Lt.c16, color:Color.c3, marginHorizontal:30, marginTop:20}}><Label style={{opacity:0, color:Color.transparent}}>{"缩进"}</Label> {c_text}</Label>
                <Label style={{fontSize:Lt.c16, color:Color.c9, marginHorizontal:30, textAlign:"center"}}>{"地址: 某某市某某区某某村镇某某大道北346号某某商业园D座603"}</Label>
                <Label style={{fontSize:Lt.c16, color:Color.c9}}>{"联系人：某小姐 18888888888"}</Label>
                <Label style={{fontSize:Lt.c16, color:Color.c9}}>{"粤ICP备18888888号-1"}</Label>
                <Fimage uri={this.state.image2} style={{minWidth:180, minHeight:180, width:"50%", height:Jpp.width/2, marginVertical:30}}/>
            </Rlist>
        </View>;
    }
}